<?php

/**
 * tipo_beca actions.
 *
 * @package    auip
 * @subpackage tipo_beca
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class tipo_becaActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->tipo_becas = Doctrine_Core::getTable('TipoBeca')
      ->createQuery('a')
      ->execute();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->tipo_beca = Doctrine_Core::getTable('TipoBeca')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->tipo_beca);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new TipoBecaForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new TipoBecaForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($tipo_beca = Doctrine_Core::getTable('TipoBeca')->find(array($request->getParameter('id'))), sprintf('Object tipo_beca does not exist (%s).', $request->getParameter('id')));
    $this->form = new TipoBecaForm($tipo_beca);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($tipo_beca = Doctrine_Core::getTable('TipoBeca')->find(array($request->getParameter('id'))), sprintf('Object tipo_beca does not exist (%s).', $request->getParameter('id')));
    $this->form = new TipoBecaForm($tipo_beca);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($tipo_beca = Doctrine_Core::getTable('TipoBeca')->find(array($request->getParameter('id'))), sprintf('Object tipo_beca does not exist (%s).', $request->getParameter('id')));
    $tipo_beca->delete();

    $this->redirect('tipo_beca/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $tipo_beca = $form->save();
      $this->getUser()->setAttribute('msg', 'Se ha ADICIONADO un NUEVO item llamado-->'.$tipo_beca->getNombre());
      $this->getUser()->setAttribute('id_tipo_beca', $tipo_beca->getId());
      $this->redirect('tipo_beca/new');
      //$this->redirect('tipo_beca/edit?id='.$tipo_beca->getId());
    }
  }
}
